Skip to content

Unnecessary requirement for project in resources#280

Open
bhouse-nexthop wants to merge 11 commits intoapache:mainfrom
bhouse-nexthop:resolve-project
Open

Unnecessary requirement for project in resources#280
bhouse-nexthop wants to merge 11 commits intoapache:mainfrom
bhouse-nexthop:resolve-project

Conversation

@bhouse-nexthop
Copy link
Collaborator

project can be learned/inherited based on the other parameters specified. The cloudstack provider was mandating project in instances where the actual cloudstack api does not require, such as on cloudstack_port_forward.

This adds proper inheritance making the project completely optional in a lot of cases. You can't create an network in a different project than its associated vpc, likewise you can't create a network acl in a different project than the vpc, so you shouldn't have to specify it.

In some instances like cloudstack_port_forward and cloudstack_network_acl the project probably should be removed completely from the schema as it serves zero actual purpose, but I chose to preserve compatibility with existing users instead.

Fixes #278

  • Ended up being "project" wasn't specified.

…it from ip address

Support both explicit project specification and automatic inheritance from IP address:
- Port forward inherits project from ip_address_id when no explicit project is set
- Uses projectid=-1 for universal IP address lookup across projects
- Updates state with inherited or explicit project during read operations
- Schema updated to mark project as Optional and Computed
- Maintains backward compatibility with existing implementations

Changes:
- Added Computed: true to project field
- Modified resourceCloudStackPortForwardCreate to fetch IP address and inherit project
- Modified resourceCloudStackPortForwardRead to handle universal project search
- Added TestAccCloudStackPortForward_projectInheritance test case
- Updated documentation with inheritance behavior and example

All 4 port forward acceptance tests passing.
When creating a network in a VPC, if no explicit project is specified,
the network will now automatically inherit the project from the VPC.

This simplifies configuration by eliminating the need to specify the
project parameter when creating networks in VPCs that belong to projects.

Changes:
- Modified resourceCloudStackNetworkCreate to fetch VPC details and
  inherit projectid when vpc_id is provided but project is not
- Modified resourceCloudStackNetworkRead to handle networks with
  inherited projects by trying projectid=-1 when no explicit project
  is set
- Added TestAccCloudStackNetwork_vpcProjectInheritance test case
- Updated documentation with inheritance behavior and example

All 14 network acceptance tests pass.
…network

Implement automatic project inheritance for cloudstack_instance resource:
- Instance inherits project from network_id when no explicit project is set
- Only applies to Advanced networking zones
- Uses projectid=-1 for universal network lookup across projects
- Updates state with inherited project during read operations

Changes:
- Modified resourceCloudStackInstanceCreate to fetch network and inherit project
- Modified resourceCloudStackInstanceRead to set project in state
- Added TestAccCloudStackInstance_networkProjectInheritance test case
- Updated documentation with inheritance behavior and example

All 12 instance acceptance tests passing.
… VPC or network

Implement automatic project inheritance for cloudstack_ipaddress resource:
- IP address inherits project from vpc_id when no explicit project is set
- IP address inherits project from network_id when no explicit project is set
- Uses projectid=-1 for universal VPC/network lookup across projects
- Updates state with inherited project during read operations

Changes:
- Modified resourceCloudStackIPAddressCreate to fetch VPC/network and inherit project
- Modified resourceCloudStackIPAddressRead to handle universal project search
- Added TestAccCloudStackIPAddress_vpcProjectInheritance test case
- Added TestAccCloudStackIPAddress_networkProjectInheritance test case
- Updated documentation with inheritance behavior and examples

All 5 IP address acceptance tests passing.
…om VPC

Implement automatic project inheritance for cloudstack_network_acl resource:
- Network ACL inherits project from vpc_id when no explicit project is set
- Uses projectid=-1 for universal VPC lookup across projects
- Updates state with inherited project during read operations
- Schema updated to mark project as Computed

Changes:
- Modified resourceCloudStackNetworkACLCreate to fetch VPC and inherit project
- Modified resourceCloudStackNetworkACLRead to handle universal project search
- Updated schema to mark project as Computed: true
- Added TestAccCloudStackNetworkACL_vpcProjectInheritance test case
- Updated documentation with inheritance behavior and example

All 5 network ACL acceptance tests passing.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the project attribute optional across several CloudStack resources by inheriting the project context from related resources (VPC, network, or IP address), aligning provider behavior with CloudStack API requirements and addressing #278.

Changes:

  • Implement project inheritance logic in port_forward, network, network_acl, ipaddress, and instance resources (plus read-path fallbacks for inherited project state).
  • Mark project as Computed where needed to prevent perpetual diffs when the provider populates state.
  • Add acceptance coverage and update docs to describe automatic project inheritance patterns.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
website/docs/r/port_forward.html.markdown Adds inheritance-focused examples and clarifies project inheritance behavior.
website/docs/r/network_acl.html.markdown Adds inheritance example and updates project argument description.
website/docs/r/network.html.markdown Documents VPC network project inheritance and updates project argument description.
website/docs/r/ipaddress.html.markdown Adds examples for VPC/network usage and documents project inheritance.
website/docs/r/instance.html.markdown Adds example demonstrating instance project inheritance from network.
cloudstack/resource_cloudstack_port_forward.go Inherits project from IP address; adjusts read/list scoping to avoid missing rules in project context.
cloudstack/resource_cloudstack_network_acl.go Inherits project from VPC and persists it in state for subsequent reads.
cloudstack/resource_cloudstack_network.go Inherits projectid from VPC during create; adds read fallback to locate inherited-project networks.
cloudstack/resource_cloudstack_ipaddress.go Inherits projectid from VPC/network during create.
cloudstack/resource_cloudstack_instance.go Inherits projectid from network during create; adds read fallback to locate inherited-project instances.
cloudstack/resource_cloudstack_port_forward_test.go Adds acceptance test for port forward project inheritance.
cloudstack/resource_cloudstack_network_test.go Adds acceptance test for network project inheritance from VPC.
cloudstack/resource_cloudstack_network_acl_test.go Adds acceptance test for network ACL project inheritance from VPC.
cloudstack/resource_cloudstack_ipaddress_test.go Adds acceptance tests for IP address project inheritance from VPC/network.
cloudstack/resource_cloudstack_instance_test.go Adds acceptance test for instance project inheritance from network.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vishesh92
Copy link
Member

@bhouse-nexthop can you check Copilot's comments? I have started the acceptance tests for this PR.

In resourceCloudStackInstanceRead, setting project before calling
setValueOrID(d, "project", ...) breaks the "preserve ID vs name"
behavior: if the user configured project as an ID, this d.Set overwrites
it with the project name, causing setValueOrID to treat it as a name and
persist the name instead of the ID.

This commit removes the early d.Set("project", vm.Project) and relies on
the existing setValueOrID(d, "project", vm.Project, vm.Projectid) later
in the function to properly preserve whether the user specified an ID or
name.
Changed 'deploy this instance to' to 'deploy this resource to' in the
project argument description to accurately reflect that this is the
Network ACL resource, not an instance resource.
Changed 'deploy this instance to' to 'deploy this network to' in the
project argument description to accurately reflect that this is the
Network resource, not an instance resource.
Changed 'deploy this instance to' to 'deploy this IP address to' in the
project argument description to accurately reflect that this is the
IP address resource, not an instance resource.
Added cloudstack_instance.web resource definition to the project
inheritance example so it can be applied as-is. The example previously
referenced cloudstack_instance.web.id without defining the resource.
The testAccCheckCloudStackNetworkACLProjectInherited function doesn't
actually validate project inheritance - it only checks the ACL name.
Since the test already has a state assertion that checks the project
attribute (resource.TestCheckResourceAttr), this helper function is
redundant and misleading. Removed the function and its call from the
test.
@bhouse-nexthop
Copy link
Collaborator Author

@bhouse-nexthop can you check Copilot's comments? I have started the acceptance tests for this PR.

done, can you re-request copilot review to validate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloudstack_port_forward always returns error (but really succeeds)

3 participants